package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.Student;
import com.example.demo.service.StudentService;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@CrossOrigin
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 根据ID查询学生信息
     */
    @GetMapping("student/{id}")
    public Result getStudentById(@PathVariable("id") Integer id) {
        List<Student> student = studentService.getStudentById(id);
        return new Result(200, "查询成功", student);
    }

    /**
     * 查询所有学生信息
     */
    @GetMapping("/studentAndClazz")
    public Result getAllStudentAndClazz() {
        List<Student> students = studentService.selectStudentWithClass();
        return new Result(200, "查询成功", students);
    }

    /**
     * 查询单个学生信息
     * @param id 学生id
     * @return 学生信息
     */
    @GetMapping("/studentClazz/{id}")
    public Result getStudentByClazzId(@PathVariable("id") Integer id) {
        Student student=studentService.selectById(id);
        return new Result(200,"查询成功",student);
    }

}
